/********************************************************************
	created:	2011/9/5
	filename: 	AppMain.cpp
	author:		Mwolf
	
	purpose:	Application loop for game
*********************************************************************/

#include "Renderer/GWRenderWindow.h"
#include "GameMain.h"
#include "GWLog.h"

#if defined GW_PLATFORM_WIN32
#include "Win32/GWAppEntry.h"
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd )
#else
int main()
#endif
{
	GameStartupParam param;
	memset( &param, 0, sizeof(param) );

#if defined GW_PLATFORM_WIN32

	LPSTR *szArgList;
	int argCount;

	szArgList = CommandLineToArgvA( GetCommandLineA(), &argCount );
	if (szArgList == NULL)
	{
		return 10;
	}

	for(int i = 0; i < argCount; i++)
	{
		if ( strcmp( szArgList[i], "-map" ) == 0 )
		{
			i++;
			
			strcpy( param.map_name, szArgList[i] );
			param.specifie_map = true;
		}
	}
#endif	// #if defined GW_PLATFORM_WIN32

	GWLog_StartRecord("klein.log");
	KleinGame()->Startup( &param );
	GWLog_EndRecord();

	while ( HandleWindowMessage() )
	{
		KleinGame()->Update();
		KleinGame()->Render();
	}

	KleinGame()->Shutdown();

	return 0;
}
